//
//  HomeOwnViewModel.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/2/3.
//

import Foundation
import SwiftUI
class AiCustomCreateViewModel : BaseViewModel {
    
    @Published var items = [AiCustomBean]()
    @Published var status = ""
    @Published var status2 = ""

    
    func doSave(bean: AiCustomBean, suc: @escaping () -> Void) {
        request {
            try check(userManager.isVip(), "需要升级Pro才能使用")
            try check((bean.name ?? "")?.isEmpty == false, "请输入名称标识")
            try check(bean.host?.isUrl() == true, "请输入正确API 地址")
            try check((bean.token ?? "")?.isEmpty == false, "请输入令牌（密钥）")
            try check((bean.model ?? "")?.isEmpty == false, "请输入模型名称")
            let dao = AiCustomDao()
            try await dao.doSave(bean: bean)
            return true
        } suc: { _ in
            showToast("保存成功")
            suc()
        } fail: {
            showToast($0.message)
        }
    }
    
    
    func doDel(bean: AiCustomBean, suc: @escaping () -> Void) {
        request {
            let dao = AiCustomDao()
            try await dao.doDel(bean: bean)
            return true
        } suc: { _ in
            showToast("删除成功")
            suc()
        } fail: {
            showToast($0.message)
        }
    }
    
}
